package com.rizhov.gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.SpringLayout;

import com.rizhov.graph.Graph;

public class TwoFieldOptionPane extends JDialog {

    public String messageOne;
    public String messageTwo;
    public int result;

    private JTextField textField;
    private JTextField textField_1;
    
    public TwoFieldOptionPane() {
	super();
	this.setModal(true);
	setBounds(0, 0, 450, 125);
	
	setModalExclusionType(ModalExclusionType.APPLICATION_EXCLUDE);
	setAlwaysOnTop(true);
	setResizable(false);
	SpringLayout springLayout = new SpringLayout();
	getContentPane().setLayout(springLayout);

	JLabel lblWeight = new JLabel("Edge weight:");
	springLayout.putConstraint(SpringLayout.NORTH, lblWeight, 10, SpringLayout.NORTH, getContentPane());
	springLayout.putConstraint(SpringLayout.WEST, lblWeight, 10, SpringLayout.WEST, getContentPane());
	getContentPane().add(lblWeight);

	JLabel lblEdgeValue = new JLabel("Edge value:");
	springLayout.putConstraint(SpringLayout.NORTH, lblEdgeValue, 24, SpringLayout.SOUTH, lblWeight);
	springLayout.putConstraint(SpringLayout.WEST, lblEdgeValue, 10, SpringLayout.WEST, getContentPane());
	getContentPane().add(lblEdgeValue);

	textField = new JTextField();
	springLayout.putConstraint(SpringLayout.NORTH, textField, 10, SpringLayout.NORTH, getContentPane());
	springLayout.putConstraint(SpringLayout.WEST, textField, 6, SpringLayout.EAST, lblWeight);
	springLayout.putConstraint(SpringLayout.EAST, textField, 359, SpringLayout.EAST, lblWeight);
	getContentPane().add(textField);
	textField.setColumns(10);

	textField_1 = new JTextField();
	springLayout.putConstraint(SpringLayout.NORTH, textField_1, 12, SpringLayout.SOUTH, textField);
	springLayout.putConstraint(SpringLayout.WEST, textField_1, 0, SpringLayout.WEST, textField);
	springLayout.putConstraint(SpringLayout.EAST, textField_1, 0, SpringLayout.EAST, textField);
	getContentPane().add(textField_1);
	textField_1.setColumns(10);

	JButton btnOk = new JButton("Ok");
	btnOk.addActionListener(new ActionListener() {
	    @Override
	    public void actionPerformed(ActionEvent e) {
		messageOne = textField.getText();
		messageTwo = textField_1.getText();
		result = JOptionPane.OK_OPTION;
		setVisible(false);
	    }
	});
	springLayout.putConstraint(SpringLayout.NORTH, btnOk, 6, SpringLayout.SOUTH, textField_1);
	springLayout.putConstraint(SpringLayout.WEST, btnOk, 105, SpringLayout.WEST, getContentPane());
	getContentPane().add(btnOk);

	JButton btnCansel = new JButton("Cansel");
	btnCansel.addActionListener(new ActionListener() {
	    @Override
	    public void actionPerformed(ActionEvent e) {
		result = JOptionPane.CANCEL_OPTION;
		setVisible(false);
	    }
	});
	springLayout.putConstraint(SpringLayout.NORTH, btnCansel, 6, SpringLayout.SOUTH, textField_1);
	springLayout.putConstraint(SpringLayout.WEST, btnCansel, 6, SpringLayout.EAST, btnOk);
	getContentPane().add(btnCansel);
	
	getRootPane().setDefaultButton(btnOk);
	
	textField.setText(String.valueOf(Graph.getInstance().getEdgeCount()));
	textField_1.setText(String.valueOf(Graph.getInstance().getEdgeCount()));
    }
}
